package com.mlz.mlzmall.ui.utils.vali;

import android.content.Context;

import com.mlz.mlzmall.ui.activity.act.main.MyApplication;

import java.util.Calendar;

/**
 * @version 1.0
 *          Created by wls_xinghuo on 2015/12/24.
 * @description
 */
public class UIUtils {

    //保存发送短信验证码时间的key
    public static final String MESSAGE_CODE_SENDTIME = "MESSAGE_CODE_SENDTIME";
    /**
     * 上下文的获取
     *
     * @return
     */
    public static Context getContext() {
        return MyApplication.getContext();
    }

    /*
    记录发送短信的时间
     */
    public static void saveTimeSendMessage() {
        long sendTime = Calendar.getInstance().getTimeInMillis();
        Tools.setLong(getContext(), MESSAGE_CODE_SENDTIME, sendTime);
    }

    /*
    清除发送短信的时间
     */
    public static void clearTimeSendMessage() {
        long sendTime = 0l;
        Tools.setLong(getContext(), MESSAGE_CODE_SENDTIME, sendTime);
    }

    /*
    60s内只能发送一次短信
     */
    public static boolean canSendMessage() {

        long time = 60000;
        long theTime = Calendar.getInstance().getTimeInMillis() - Tools.getLong(getContext(), MESSAGE_CODE_SENDTIME, 0);

        if (theTime > time) {
            return true;
        }
        return false;
    }
}
